 <!--
* description: 善意索赔管理
* author: wangjuan
* createdDate: 2020-11-17
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-show-more-btn="true"
    />

    <Edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
    <Add
      :key="editPopupsKey1"
      :popups-visible="editPopupsVisible1"
      @close="close1"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import api from "@/api/subsidyManage";
import Vue from "vue";
import { exportExcel } from "@/utils/getTimeString.js";
import { vehiclePdiPriceInquirys } from "@/api/se/vehiclePdiPriceInquiry";

export default {
  name: "GoodFaithClaimManagement",

  components: {
    OneTableTemplate,
    Edit: () => import("./edit"),
    Add: () => import("./add")
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function() {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      // 网格查询API配置对象
      apiConfig: vehiclePdiPriceInquirys.findMainList,
      editRowData: {},
      editPopupsVisible: false,
      editPopupsVisible1: false,
      titleName: "区域审核",
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          size: "small",
          name: "add",
          clickEvent: () => this.add1(),
          text: "新建",
          position: "left" // 新增
        },
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true
        },

        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right" // 重置
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
              {
                compKey: "compKey2",
                labelName: "申请单号：",
                codeField: "complainCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true
              },

              {
                compKey: "compKey4",
                labelName: "VIN：",
                codeField: "vin",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true
              },
              {
                compKey: "compKey5",
                labelName: "车牌号：",
                codeField: "carLicense",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true
              },
              {
                compKey: "compKey6",
                labelName: "申请日期：",
                codeField: "createdStartTime,createdEndTime",
                component: () =>
                  import("@/components/org/datePicker/andtDatePicker"),
                type: "YYYY-MM-DD",
                format: "yyyy-MM-dd",
                isMul: false,
                isMust: true
              },
              {
                compKey: "compKey6",
                labelName: "状态：",
                codeField: "complainStatusCode",
                component: () => import("@/components/org/commonSelect"),
                customObj: {
                  api: vehiclePdiPriceInquirys.findStatus
                },
                oFields: "complainStatusCode,complainStatus",
                type: "dropdownList",
                isMul: false,
                isMust: false
              },
              {
                compKey: "compKey6",
                labelName: "投诉单号：",
                codeField: "ccCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false
              },
              {
                compKey: "compKey6",
                labelName: "客户姓名：",
                codeField: "custName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false
              },
              {
                compKey: "compKey6",
                labelName: "客户手机：",
                codeField: "phone",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: false
              }
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "subsidyId",
                label: "主键ID",
                hidden: true,
                alwaysHidden: true
              },
              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true
              },
              {
                prop: "controlBtn",
                label: "操作",
                width: 100,
                fixed: true,
                isComponent: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "审核",
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: index => this.edit(index)
                  },
                  {
                    compKey: "propKey1",
                    labelName: "详情",
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: index => this.look(index)
                  }
                ]
              },
              {
                prop: "complainCode",
                label: "申请单号"
              },
              {
                prop: "custName",
                label: "客户姓名"
              },
              {
                prop: "phone",
                label: "客户手机"
              },
              {
                prop: "ccCode",
                label: "投诉单号"
              },
              {
                prop: "vin",
                label: "VIN"
              },
              {
                prop: "carLicense",
                label: "车牌号"
              },
              {
                prop: "complainStatus",
                label: "状态"
              },
              {
                prop: "createdDate",
                label: "申请日期"
              },
              {
                prop: "auditDate",
                label: "审核日期"
              }
            ],

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          complainCode: "",
          vin: "",
          carLicense: "",
          createdStartTime: "",
          createdEndTime: "",
          complainStatusCode: "",
          ccCode: "",
          custName: "",
          phone: ""
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    };
  },

  mounted() {
    // 列表查询
    this.queryTable(1);

    this.$refs.multipleTable.list = [
      {
        index: 1,
        type: true,
        start: false
      }
    ];
  },

  methods: {
    edit(index) {
      this.editPopupsState = "edit";
      this.editPopupsVisible = true;
      this.editPopupsVisible1 = false;
      this.editRowData = this.$refs["multipleTable"].list[index];
    },
    look(index) {
      this.editPopupsState = "look";
      this.editPopupsVisible = true;
      this.editPopupsVisible1 = false;
      this.editRowData = this.$refs["multipleTable"].list[index];
    },
    add1() {
      this.editPopupsVisible1 = true;
    },
    close() {
      this.editPopupsVisible = false;
      this.queryTable(1);
    },
    close1() {
      this.editPopupsVisible1 = false;
      this.queryTable(1);
    },
    exportExcel111() {
      exportExcel(
        this.formField,
        vehiclePdiPriceInquirys.claimDeductApplyExcel.APIUrl,
        vehiclePdiPriceInquirys.claimDeductApplyExcel.ServiceCode,
        "索赔倒扣查询"
      );
    }
  }
};
</script>
